/*
 * @Descripttion: 
 * @version: 
 * @Author: mmzhang
 * @Date: 2021-07-23 09:45:29
 * @LastEditTime: 2022-01-24 14:10:06
 */

import table from '@/components/dt/table/render.js'
import nameOpt from '@/biz/option/name.js'
import dateOpt from '@/biz/option/date.js'
import Opt from '@/components/dt/info/Opt.js'
import dt from '@dt/dt'
import channelMgr from '@/biz/channel/channel'
let _this = null


class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
    console.log(_this.planChannelChannelData,
      '_this.planChannelChannelDatabbbbbbbbbbbbbbbbbb');
  }

  createAll() {
    this.all = [
      {
        title: '序号',
        type: 'index',
        width: 80,
        align: 'center',
      },
      // {
      //   title: '渠道分类',
      //   field: 'channelType',
      //   minWidth: 120,
      //   align: 'center',
      //   cell: {
      //     text: {
      //       type: 'dict',
      //       key: 'channelType'
      //     }
      //   }
      // },
      {
        title: '渠道名称',
        field: 'channelName',
        minWidth: 150,
        align: 'center',
        header: {
          filter: {
            title: '渠道名称',
            key: 'channelName',
            placeholder: '请输入',
            input: {},
          }
        }
      },

      {
        title: '自获客打法',
        field: 'planName',
        minWidth: 160,
        align: 'center',
        header: {
          filter: {
            title: '自获客打法',
            key: 'planIds',
            placeholder: '请选择',
            select: {
              options: _this.planChannelChannelData,
              multiple: true,
              filterable: true,
            }

          }
        }

      }, {
        field: 'isTakeLook',
        minWidth: 160,
        align: 'center',
        header: {
          filter: {
            title: '是否渠道带看',
            key: 'isTakeLook',
            placeholder: '请选择',
            select: {
              options: [
                { key: '1', value: '是' },
                { key: '0', value: '否' },
              ]
            }
          }
        },
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: params.row.isTakeLook == '0' ? '否' : '是'
            })
          }
        }

      }, {
        field: 'isNetAcquire',
        minWidth: 160,
        align: 'center',
        header: {
          filter: {
            title: '是否网络获客',
            key: 'isNetAcquire',
            placeholder: '请选择',
            select: {
              options: [
                { key: '1', value: '是' },
                { key: '0', value: '否' },
              ]
            }
          }
        },
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: params.row.isNetAcquire == '0' ? '否' : '是'
            })
          }
        }
      },
      {
        title: '是否线索渠道',
        field: 'isClueChannel',
        minWidth: 160,
        align: 'center',
        header: {
          filter: {
            title: '是否线索渠道',
            key: 'isClueChannel',
            placeholder: '请选择',
            select: {
              options: [
                { key: '1', value: '是' },
                { key: '0', value: '否' },
              ]
            }
          }
        },
      },
      {
        title: '合作类型',
        field: 'cooperationTypeName',
        minWidth: 120,
        align: 'center',
        header: {
          filter: {
            title: '合作类型',
            key: 'cooperationTypes',
            placeholder: '请选择',
            select: {
              multiple: true,
              options: dt.dictInfo().cooperationTypeFinal
            }
          }
        },


      },
      {
        title: '合作日期',
        field: '',
        minWidth: 220,
        align: 'center',
        header: {
          filter: dateOpt.range({
            title: '合作日期',
            placeholder: '请选择合作日期',
            startKey: 'cooperationStartDate',
            endKey: 'cooperationEndDate',
            disabled: (date) => {
              return date.valueOf() > new Date().getTime()
            },
            check: (val) => {
              if (_this.$tool.dateDiff(val.cooperationStartDate, val
                  .cooperationEndDate).Y >= 2) {
                // 日期最大跨度两年
                _this.$Message.warning('合作日期跨度至多两年。')
              }
              return !(_this.$tool.dateDiff(val.cooperationStartDate, val
                .cooperationEndDate).Y >= 2)
            }
          }),
        },
        slots: {
          default: (params, h) => {
            let startDate = params.row.cooperationStartDate,
              endDate = params.row.cooperationEndDate
            return table.cell.text(h, {
              value: !startDate && !endDate ? '' :
                `${startDate? startDate: ' - '}至${endDate? endDate: ' - '}`
            })
          }
        }
      },
      {
        title: '渠道费用',
        // field: 'channelName',
        minWidth: 120,
        align: 'center',
        header: {
          filter: {
            title: '渠道费用',
            key: 'channelCostTypes',
            placeholder: '请选择',
            select: {
              multiple: true,
              options: dt.dictInfo().channelCostType
            }
          }
        },


        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: params.row.channelCostType === '3' ? '浮动' : params.row
                .channelCostValue && params.row.unit &&
                `${params.row.channelCostValue}${params.row.unit}`
            })
          }
        }
      },
      {
        title: '操作时间',
        field: 'updateTime',
        width: 200,
        align: 'center',
        header: {
          filter: dateOpt.range({
            title: '操作时间',
            placeholder: '请选择操作时间',
            startKey: 'operationStartDate',
            endKey: 'operationEndDate',
            disabled: (date) => {
              return date.valueOf() > new Date().getTime()
            },
            check: (val) => {
              if (_this.$tool.dateDiff(val.operationStartDate, val
                  .operationEndDate).Y >= 2) {
                // 日期最大跨度两年
                _this.$Message.warning('操作时间跨度至多两年。')
              }
              return !(_this.$tool.dateDiff(val.operationStartDate, val
                .operationEndDate).Y >= 2)
            }
          }),
        },
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: params.row.updateTime.substr(0, 16)
            })
          }
        }
      },
      {
        title: '操作人',
        field: 'updaterName',
        width: 120,
        align: 'center',
      },
      {
        title: '状态',
        field: 'validate',
        width: 100,
        align: 'center',
        header: {
          filter: {
            title: '状态',
            key: 'validate',
            placeholder: '请选择',
            select: {
              options: [
                { key: '1', value: '启用' },
                { key: '2', value: '禁用' },
              ]
            }
          }
        },
        slots: {
          default: (params, h) => {
            return table.cell.text(h, {
              value: params.row.validate == 1 ? '启用' : '禁用'
            })
          }
        }
      },
      {
        title: '操作',
        field: 'operation',
        width: 200,
        align: 'center',
        fixed: 'right',
        slots: {
          default: (params, h) => {
            let flag = params.row.isClueChannel.indexOf('是')
            let btns = []
            btns.push({
              title: '查看',
              event: 'viewChannel',
              data: params.row
            })

            btns.push({
              title: _this.unlocking('0102010402') && flag == -1 ? '编辑' : '',
              event: 'editChannel',
              data: params.row
            })

            btns.push({
              title: _this.unlocking('0102010403') && flag == -1 ? '删除' : '',
              event: 'delChannel',
              data: params.row
            })

            return table.cell.btns(_this, h, btns)
          }
        }
      }
    ]
  }

}

export default Column